import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

// 全局颜色
final lxColorScheme = Theme.of(Get.context!).colorScheme;
final lxTheme = Theme.of(Get.context!);

// 扩展ColorScheme，添加自定义颜色
extension CustomColorScheme on ColorScheme {
  /// 主题Appbar颜色
  Color get themeAppbarColor => brightness == Brightness.light
      ? LightTheme.themeAppbarColor
      : DarkTheme.themeAppbarColor;

  /// 主题字体颜色（如：dark-橙、light-白）
  Color get themeTextColor => brightness == Brightness.light
      ? LightTheme.themeTextColor
      : DarkTheme.themeTextColor;

  /// 超链接文本颜色 - 主颜色
  Color get linkTextColor => brightness == Brightness.light
      ? LightTheme.linkTextColor
      : DarkTheme.linkTextColor;

  /// 超链接文本颜色 - 次级色
  Color get subLinkTextColor => brightness == Brightness.light
      ? LightTheme.subLinkTextColor
      : DarkTheme.subLinkTextColor;

  /// widget背景色 - 主颜色
  Color get blockColor => brightness == Brightness.light
      ? LightTheme.blockColor
      : DarkTheme.blockColor;

  /// widget背景色 - 次级色
  Color get subBlockColor => brightness == Brightness.light
      ? LightTheme.subBlockColor
      : DarkTheme.subBlockColor;

  /// 标题文本颜色
  Color get titleColor => brightness == Brightness.light
      ? LightTheme.titleColor
      : DarkTheme.titleColor;

  /// 副标题文本颜色
  Color get subtitleColor => brightness == Brightness.light
      ? LightTheme.subtitleColor
      : DarkTheme.subtitleColor;

  /// 标题颜色反转（light-深色背景使用，dark-浅色背景使用）
  Color get invertTitleColor => brightness == Brightness.light
      ? LightTheme.invertTitleColor
      : DarkTheme.invertTitleColor;

  Color get iconColor => brightness == Brightness.light
      ? LightTheme.iconColor
      : DarkTheme.iconColor;

  /// BottomNavigationBarItem图标选中颜色
  Color get bottomNavigationBarActiveColor => brightness == Brightness.light
      ? LightTheme.bottomNavigationBarActiveColor
      : DarkTheme.bottomNavigationBarActiveColor;

  /// 按钮文本颜色
  Color get buttonTextColor => brightness == Brightness.light
      ? LightTheme.buttonTextColor
      : DarkTheme.buttonTextColor;

  /// 按钮背景颜色
  Color get buttonBackgroundColor => brightness == Brightness.light
      ? LightTheme.buttonBackgroundColor
      : DarkTheme.buttonBackgroundColor;

  /// 次级按钮文本颜色
  Color get subButtonTextColor => brightness == Brightness.light
      ? LightTheme.subButtonTextColor
      : DarkTheme.subButtonTextColor;

  /// 次级按钮背景颜色
  Color get subButtonBackgroundColor => brightness == Brightness.light
      ? LightTheme.subButtonBackgroundColor
      : DarkTheme.subButtonBackgroundColor;

  ///
  /// 车辆模块
  ///
  /// 车辆 - 速度字体颜色
  Color get vehicleHomeSpeedColor => brightness == Brightness.light
      ? LightTheme.vehicleHomeSpeedColor
      : DarkTheme.vehicleHomeSpeedColor;

  /// 车辆 - 速度背景图片颜色
  Color get vehicleHomeSpeedBackgroundColor => brightness == Brightness.light
      ? LightTheme.vehicleHomeSpeedBackgroundColor
      : DarkTheme.vehicleHomeSpeedBackgroundColor;

  /// 列表图标颜色
  Color get itemIconColor => brightness == Brightness.light
      ? LightTheme.itemIconColor
      : DarkTheme.itemIconColor;

  /// 列表按钮颜色
  Color get itemBtnColor => brightness == Brightness.light
      ? LightTheme.itemBtnColor
      : DarkTheme.itemBtnColor;

  /// 按钮图标颜色
  Color get btnIconColor => brightness == Brightness.light
      ? LightTheme.btnIconColor
      : DarkTheme.btnIconColor;

  /// 电池电量背景色
  Color get batteryLevelBackgroundColor => brightness == Brightness.light
      ? LightTheme.batteryLevelBackgroundColor
      : DarkTheme.batteryLevelBackgroundColor;

  /// 电池电量前景色
  Color get batteryLevelForegroundColor => brightness == Brightness.light
      ? LightTheme.batteryLevelForegroundColor
      : DarkTheme.batteryLevelForegroundColor;

  Color get tabbarIndicatorColor => brightness == Brightness.light
      ? LightTheme.tabbarIndicatorColor
      : DarkTheme.tabbarIndicatorColor;

  /// 删除栏背景色
  Color get deleteBackgroundColor => brightness == Brightness.light
      ? LightTheme.deleteBackgroundColor
      : DarkTheme.deleteBackgroundColor;

  /// 删除栏背景色
  Color get redColor =>
      brightness == Brightness.light ? LightTheme.redColor : DarkTheme.redColor;

  /// 删除栏背景色
  Color get greenColor => brightness == Brightness.light
      ? LightTheme.greenColor
      : DarkTheme.greenColor;

  /// 删除栏背景色
  Color get orangeColor => brightness == Brightness.light
      ? LightTheme.orangeColor
      : DarkTheme.orangeColor;

  ///
  /// 聊天模块
  ///
  /// 客服 - 文本内容背景颜色

  Color get chatCurrentTextBackgroundColor => brightness == Brightness.light
      ? LightTheme.chatCurrentTextBackgroundColor
      : DarkTheme.chatCurrentTextBackgroundColor;

  /// 客服 - 文本内容背景颜色
  Color get chatTextBackgroundColor => brightness == Brightness.light
      ? LightTheme.chatTextBackgroundColor
      : DarkTheme.chatTextBackgroundColor;

  /// 客服 - 占位符颜色(输入框为灰底，所以颜色需加深)
  Color get chatHintColor => brightness == Brightness.light
      ? LightTheme.chatHintColor
      : DarkTheme.chatHintColor;

  /// 客服 - 占位符颜色(输入框为灰底，所以颜色需加深)
  Color get chatWarningColor => brightness == Brightness.light
      ? LightTheme.chatWarningColor
      : DarkTheme.chatWarningColor;

  /// 灯效编辑 - 背景色
  Color get lightEffectEditBackgroundColor => brightness == Brightness.light
      ? LightTheme.lightEffectEditBackgroundColor
      : DarkTheme.lightEffectEditBackgroundColor;

  /// 灯效编辑 - 灯珠默认颜色
  Color get lightDefaultColor => brightness == Brightness.light
      ? LightTheme.lightDefaultColor
      : DarkTheme.lightDefaultColor;

  /// 公共按钮颜色
  Color get commonButtonColor => brightness == Brightness.light
      ? LightTheme.commonButtonColor
      : DarkTheme.commonButtonColor;

  /// Slider背景色
  Color get sliderBackgroundColor => brightness == Brightness.light
      ? LightTheme.sliderBackgroundColor
      : DarkTheme.sliderBackgroundColor;

  /// Slider前景色
  Color get sliderForegroundColor => brightness == Brightness.light
      ? LightTheme.sliderForegroundColor
      : DarkTheme.sliderForegroundColor;

  /// 默认光标颜色
  Color get cursorColor => brightness == Brightness.light
      ? LightTheme.cursorColor
      : DarkTheme.cursorColor;

  /// 输入框文本颜色
  Color get textFieldTextColor => brightness == Brightness.light
      ? LightTheme.textFieldTextColor
      : DarkTheme.textFieldTextColor;

  /// dialog 分割线颜色
  Color get dialogDividerColor => brightness == Brightness.light
      ? LightTheme.dialogDividerColor
      : DarkTheme.dialogDividerColor;

  /// dialog 取消栏分割线颜色
  Color get dialogCancelDividerColor => brightness == Brightness.light
      ? LightTheme.dialogCancelDividerColor
      : DarkTheme.dialogCancelDividerColor;
}

class LightTheme {
  static const brightness = Brightness.light;

  ///
  /// 系统级颜色
  ///

  /// 应用程序主要颜色，导航栏等
  static const primaryColor = Color(0xFFFFFFFF);

  /// 次级色，大多数Widget的颜色，如进度条、开关等
  static const secondaryColor = Color(0xFF2B2B33);

  /// 页面背景色（通常出现在可滚动内容后面的颜色）
  static const backgroundColor = Color(0xFFFFFFFF);

  /// 应用程序空白页背景色
  static const scaffoldBackgroundColor = Color(0xFFFFFFFF);

  /// dialog背景色
  static const dialogBackgroundColor = Color(0xFFFFFFFF);

  /// card背景色
  static const cardColor = hintColor;

  /// 阴影颜色
  static const shadowColor = Color.fromRGBO(0, 0, 0, 0.05);

  /// 占位符字体颜色
  static const hintColor = Color(0xFFE4E4E4);

  /// drivider颜色
  static const dividerColor = Color(0xFFE8E8E8);

  /// Tabbar选中字体颜色
  static const selectedItemColor = Color(0xFF494949);

  /// Tabbar未选中字体颜色
  static const unselectedItemColor = Color(0xFF929292);

  /// 错误提示颜色
  static const errorColor = Color(0xFFFF1616);

  ///
  /// 自定义颜色
  ///

  /// 主题Appbar颜色
  static const themeAppbarColor = Color(0xFFEA5421);

  /// 主题字体颜色（如：dark-橙、light-白）
  static const themeTextColor = Color(0xFFEA5421);

  /// 超链接文本颜色 - 主颜色
  static const linkTextColor = Color(0xFFEA5421);

  /// 超链接文本颜色 - 次级色
  static const subLinkTextColor = Color(0xFF929292);

  /// widget背景色 - 主颜色
  static const blockColor = Color(0xFF343541);

  /// widget背景色 - 次级色
  static const subBlockColor = Color(0xFFFFFFFF);

  /// 标题文本颜色
  static const titleColor = Color(0xFF494949);

  /// 副标题文本颜色
  static const subtitleColor = Color(0xFF929292);

  /// 标题颜色反转（深色背景使用）
  static const invertTitleColor = Color(0xFFFFFFFF);

  /// icon颜色
  static const iconColor = Color(0xFFD2D2D2);

  /// BottomNavigationBarItem图标选中颜色
  static const bottomNavigationBarActiveColor = Color(0xFFEA5421);

  /// 按钮文本颜色
  static const buttonTextColor = Color(0xFFFFFFFF);

  /// 按钮背景颜色
  static const buttonBackgroundColor = Color(0xFFEA5421);

  /// 次级按钮文本颜色
  static const subButtonTextColor = Color(0xFF212529);

  /// 次级按钮背景颜色
  static const subButtonBackgroundColor = Color(0xFFF8F9FA);

  /// 车辆 - 速度字体颜色
  static const vehicleHomeSpeedColor = Color(0xFFEA5421);

  /// 车辆 - 速度背景图片颜色
  static const vehicleHomeSpeedBackgroundColor = Color(0xFFEEEEEE);

  /// 列表图标颜色
  static const itemIconColor = Color(0xFF4D4D4D);

  /// 列表按钮颜色
  static const itemBtnColor = Color(0xFFEA5421);

  /// 按钮图标颜色
  static const btnIconColor = Color(0xFF4D4D4D);

  /// 电池电量背景色
  static const batteryLevelBackgroundColor = Color(0xFFD9D9D9);

  /// 电池电量前景色
  static const batteryLevelForegroundColor = Color(0xFF32CD32);

  /// tabbarIndicatorColor
  static const tabbarIndicatorColor = Color(0xFFEA5421);

  /// 客服 - 文本内容背景颜色
  static const chatCurrentTextBackgroundColor = Color(0xFFEA5421);

  /// 客服 - 文本内容背景颜色
  static const chatTextBackgroundColor = Color(0xFFE8E8E8);

  /// 客服 - 占位符颜色(输入框为灰底，所以颜色需加深)
  static const chatHintColor = Color(0xFFBBBBBB);

  /// 客服 - 警告背景色（排队人数）
  static const chatWarningColor = Color(0xFFFFA500);

  /// 灯效编辑 - 背景色
  static const lightEffectEditBackgroundColor =
      Color.fromARGB(255, 245, 245, 245);

  /// 灯效编辑 - 灯珠默认颜色
  static const lightDefaultColor = Color(0xFFA9A9A9);

  /// 公共按钮颜色
  static const commonButtonColor = titleColor;

  /// Slider背景色
  static const sliderBackgroundColor = Color(0xFFE8E8E8);

  /// Slider前景色
  static const sliderForegroundColor = Color(0xFFEA5421);

  /// 默认光标颜色
  static const cursorColor = Color(0xFFEA5421);

  /// 输入框文本颜色
  static const textFieldTextColor = Color(0xFF929292);

  /// dialog 分割线颜色
  static const dialogDividerColor = Color(0xFFE8E8E8);

  /// dialog 取消栏分割线颜色
  static const dialogCancelDividerColor = Color(0xFFE8E8E8);

  /// 删除栏背景色
  static const deleteBackgroundColor = Color(0xFFFF1616);

  /// 自定义颜色 - 红
  static const redColor = Color(0xFFFF0000);

  /// 自定义颜色 - 绿
  static const greenColor = Color(0xFF008000);

  /// 自定义颜色 - 橙
  static const orangeColor = Color(0xFFFFA500);

  ///
  /// 字体
  ///

  /// Appbar标题
  static const appbarTitleStyle =
      TextStyle(fontSize: 17.0, fontWeight: FontWeight.w500, color: titleColor);

  /// Dialog标题
  static const dialogTitleStyle =
      TextStyle(fontSize: 17.0, fontWeight: FontWeight.w500, color: titleColor);

  /// 列表标题
  static const listTitleStyle =
      TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500, color: titleColor);

  /// 列表副标题
  static const listSubtitleStyle = TextStyle(
      fontSize: 14.0, fontWeight: FontWeight.w500, color: subtitleColor);

  /// 列表内容
  static const listContentStyle = TextStyle(
      fontSize: 12.0, fontWeight: FontWeight.w400, color: subtitleColor);

  /// 默认输入框字体
  static TextStyle textFieldStyle = TextStyle(
      fontSize: min(17.w, 25),
      fontWeight: FontWeight.w400,
      color: const Color(0xFF929292));

  /// 车辆信息（设置/关于车辆/电池信息等）头部标题
  static const vehicleInfoHeaderStyle =
      TextStyle(fontSize: 24.0, fontWeight: FontWeight.w600, color: titleColor);

  /// 车辆信息（设置/关于车辆/电池信息等）标题
  static const vehicleInfoTitleStyle =
      TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500, color: titleColor);

  /// 车辆信息（设置/关于车辆/电池信息等）内容
  static const vehicleInfoValueStyle = TextStyle(
      fontSize: 16.0, fontWeight: FontWeight.w500, color: subtitleColor);
}

class DarkTheme {
  static const brightness = Brightness.dark;

  ///
  /// 系统级颜色
  ///

  /// 应用程序主要颜色，导航栏等
  static const primaryColor = Color(0xFF131315);

  /// 次级色，大多数Widget的颜色，如进度条、开关等
  static const secondaryColor = Color(0xFF2B2B33);

  /// 页面背景色（通常出现在可滚动内容后面的颜色）
  static const backgroundColor = Color(0xFF0B0B0B);

  /// 应用程序空白页背景色
  static const scaffoldBackgroundColor = Color(0xFF0B0B0B);

  /// dialog背景色
  static const dialogBackgroundColor = Color(0xFF131315);

  /// card背景色
  static const cardColor = secondaryColor;

  /// 阴影颜色
  static const shadowColor = Color.fromRGBO(0, 0, 0, 0.05);

  /// 占位符字体颜色
  static const hintColor = Color(0xFF4D4D53);

  /// drivider颜色
  static const dividerColor = Color(0xFF4D4D53);

  /// Tabbar选中字体颜色
  static const selectedItemColor = Color(0xFFD2D2D2);

  /// Tabbar未选中字体颜色
  static const unselectedItemColor = Color(0xFFA6AAB2);

  /// 错误提示颜色
  static const errorColor = Color(0xFFFF1616);

  ///
  /// 自定义颜色
  ///

  /// 主题Appbar颜色
  static const themeAppbarColor = Color(0xFF1C1C21);

  /// 主题字体颜色（如：dark-橙、light-白）
  static const themeTextColor = Color(0xFFD2D2D2);

  /// 超链接文本颜色 - 主颜色
  static const linkTextColor = Color(0xFF6B7C97);

  /// 超链接文本颜色 - 次级色
  static const subLinkTextColor = Color(0xFF6B7C97);

  /// widget背景色 - 主颜色
  static const blockColor = Color(0xFF131315);

  /// widget背景色 - 次级色
  static const subBlockColor = Color(0xFF1C1C21);

  /// 标题文本颜色
  static const titleColor = Color(0xFFD2D2D2);

  /// 副标题文本颜色
  static const subtitleColor = Color(0xFF888888);

  /// 标题颜色反转（深色背景使用）
  static const invertTitleColor = Color(0xFF494949);

  /// icon颜色
  static const iconColor = Color(0xFFD2D2D2);

  /// BottomNavigationBarItem图标选中颜色
  static const bottomNavigationBarActiveColor = Color(0xFFD2D2D2);

  /// 按钮文本颜色
  static const buttonTextColor = Color(0xFFD2D2D2);

  /// 按钮背景颜色
  static const buttonBackgroundColor = Color(0xFF1F1F22);

  /// 次级按钮文本颜色
  static const subButtonTextColor = Color(0xFF797979);

  /// 次级按钮背景颜色
  static const subButtonBackgroundColor = Color(0xFF1B1B1D);

  /// 车辆 - 速度字体颜色
  static const vehicleHomeSpeedColor = Color(0xFFD9D9D9);

  /// 车辆 - 速度背景图片颜色
  static const vehicleHomeSpeedBackgroundColor = Color(0xFF1D1D21);

  /// 列表图标颜色
  static const itemIconColor = Color(0xFFFFFFFF);

  /// 列表按钮颜色
  static const itemBtnColor = Color(0xFF797979);

  /// 按钮图标颜色
  static const btnIconColor = Color(0xFFD2D2D2);

  /// 电池电量背景色
  static const batteryLevelBackgroundColor = Color(0xFF1D1D1D);

  /// 电池电量前景色
  static const batteryLevelForegroundColor = Color(0xFF333333);

  /// tabbarIndicatorColor
  static const tabbarIndicatorColor = Color(0xFFD2D2D2);

  /// 客服 - 文本内容背景颜色
  static const chatCurrentTextBackgroundColor = Color(0xFF1F1F22);

  /// 客服 - 文本内容背景颜色
  static const chatTextBackgroundColor = Color(0xFF1B1B1D);

  /// 客服 - 占位符颜色
  static const chatHintColor = hintColor;

  /// 客服 - 警告背景色（排队人数）
  static const chatWarningColor = hintColor;

  /// 灯效编辑 - 背景色
  static const lightEffectEditBackgroundColor = subBlockColor;

  /// 灯效编辑 - 灯珠默认颜色
  static const lightDefaultColor = Color(0xFF4D4D53);

  /// 公共按钮颜色
  static const commonButtonColor = titleColor;

  /// Slider背景色
  static const sliderBackgroundColor = Color(0xFF333333);

  /// Slider前景色
  static const sliderForegroundColor = Color(0xFF777777);

  /// 默认光标颜色
  static const cursorColor = Color(0xFFD2D2D2);

  /// 输入框文本颜色
  static const textFieldTextColor = Color(0xFF929292);

  /// dialog 分割线颜色
  static const dialogDividerColor = Color(0xFF2b2b2b);

  /// dialog 取消栏分割线颜色
  static const dialogCancelDividerColor = Color(0xFF0B0B0B);

  /// 删除栏背景色
  static const deleteBackgroundColor = Color(0xFF800000);

  /// 自定义颜色 - 红
  static const redColor = Color(0xFF8B0000);

  /// 自定义颜色 - 绿
  static const greenColor = Color(0xFF006400);

  /// 自定义颜色 - 橙
  static const orangeColor = Color(0xFFFF8C00);

  ///
  /// 字体
  ///

  /// Appbar标题
  static const appbarTitleStyle =
      TextStyle(fontSize: 17.0, fontWeight: FontWeight.w500, color: titleColor);

  /// Dialog标题
  static const dialogTitleStyle =
      TextStyle(fontSize: 17.0, fontWeight: FontWeight.w500, color: titleColor);

  /// 列表标题
  static const listTitleStyle =
      TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500, color: titleColor);

  /// 列表副标题
  static const listSubtitleStyle = TextStyle(
      fontSize: 14.0, fontWeight: FontWeight.w500, color: subtitleColor);

  /// 列表内容
  static const listContentStyle = TextStyle(
      fontSize: 12.0, fontWeight: FontWeight.w400, color: subtitleColor);

  /// 默认输入框字体
  static TextStyle textFieldStyle = TextStyle(
      fontSize: min(17.w, 25),
      fontWeight: FontWeight.w400,
      color: const Color(0xFFD9D9D9));

  /// 车辆信息（设置/关于车辆/电池信息等）头部标题
  static const vehicleInfoHeaderStyle =
      TextStyle(fontSize: 24.0, fontWeight: FontWeight.w600, color: titleColor);

  /// 车辆信息（设置/关于车辆/电池信息等）标题
  static const vehicleInfoTitleStyle = TextStyle(
      fontSize: 16.0, fontWeight: FontWeight.w500, color: subtitleColor);

  /// 车辆信息（设置/关于车辆/电池信息等）内容
  static const vehicleInfoValueStyle =
      TextStyle(fontSize: 16.0, fontWeight: FontWeight.w500, color: titleColor);
}

///
/// ThemeData扩展
///
extension CustomThemeData on ThemeData {
  /// Appbar标题
  TextStyle get appbarTitleStyle => brightness == Brightness.light
      ? LightTheme.appbarTitleStyle
      : DarkTheme.appbarTitleStyle;

  /// Dialog标题
  TextStyle get dialogTitleStyle => brightness == Brightness.light
      ? LightTheme.dialogTitleStyle
      : DarkTheme.dialogTitleStyle;

  /// 列表标题
  TextStyle get listTitleStyle => brightness == Brightness.light
      ? LightTheme.listTitleStyle
      : DarkTheme.listTitleStyle;

  /// 列表副标题
  TextStyle get listSubtitleStyle => brightness == Brightness.light
      ? LightTheme.listSubtitleStyle
      : DarkTheme.listSubtitleStyle;

  /// 列表内容
  TextStyle get listContentStyle => brightness == Brightness.light
      ? LightTheme.listContentStyle
      : DarkTheme.listContentStyle;

  /// 默认输入框字体
  TextStyle get textFieldStyle => brightness == Brightness.light
      ? LightTheme.textFieldStyle
      : DarkTheme.textFieldStyle;

  /// 车辆信息头部标题
  TextStyle get vehicleInfoHeaderStyle => brightness == Brightness.light
      ? LightTheme.vehicleInfoHeaderStyle
      : DarkTheme.vehicleInfoHeaderStyle;

  /// 车辆信息标题
  TextStyle get vehicleInfoTitleStyle => brightness == Brightness.light
      ? LightTheme.vehicleInfoTitleStyle
      : DarkTheme.vehicleInfoTitleStyle;

  /// 车辆信息内容
  TextStyle get vehicleInfoValueStyle => brightness == Brightness.light
      ? LightTheme.vehicleInfoValueStyle
      : DarkTheme.vehicleInfoValueStyle;
}
